<style lang="scss" scoped>
	.content {

		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.nav {
		width: 100%;
		position: fixed;
		top: 0;
		left: 0;
		padding-bottom: 10rpx;
		border-bottom: 1px solid #dee2ee;
		background-color: white;
		z-index: 999;
	}

	.top {
		padding: 20rpx 30rpx;
	}

	.search {
		width: 554rpx;
		height: 76rpx;
		background: #f4f5f7;
		border: 2rpx solid #f5f5f5;
		border-radius: 46rpx;
		padding: 20rpx;

		.ipt {
			flex: 1;
		}
	}


	.lists {
		margin-bottom: 50rpx;

		.list {
			width: 690rpx;

			opacity: 1;
			background: #ffffff;
			border-radius: 20rpx;
			box-shadow: 0rpx 30rpx 18rpx -14rpx #e6ebf2;
			overflow: hidden;
			margin-top: 30rpx;

			.head {
				width: 100%;

				.tips {
					width: 136rpx;
					border-bottom: 1px solid #eee;
					border-right: 1px solid #eee;

					.tip {
						height: 68rpx;
					}

					.actived {
						background: #fa5151;
						color: #fff;
					}
				}

				.ordernum {

					padding: 0 20rpx;
					flex: 1;
					border-bottom: 1px solid #eee;

					>view {
						height: 68rpx;
					}

					.between-flex {
						width: 100%;
					}
				}
			}

			.contains {
				width: 100%;
				padding: 20rpx;

				.text {
					width: 620rpx;
					line-height: 60rpx;

				}
			}


		}
	}

	.line {
		>view {
			width: 50%;
		}
	}

	.line2 {
		width: 100%;
		align-items: flex-start;

		.progress {
			width: 395rpx;
			margin: 0 10rpx;
			transform: translateY(-6rpx);
		}

		.row1 {
			width: 100%;
		}
	}

	.btns {
		width: 100%;
		height: 100rpx;
		border-top: 2rpx solid #f5f7fa;

		.btn {
			width: 33.33%;
			height: 100rpx;
			border-right: 2rpx solid #f5f7fa;

			>view {
				position: relative;

				image {
					width: 38rpx;
					height: 38rpx;
					margin-right: 10rpx;
				}

				.num {
					padding: 0 10rpx;
					height: 34rpx;
					background: #fa5151;
					border-radius: 8rpx 8rpx 8rpx 0rpx;
					box-shadow: 0rpx 2rpx 8rpx 0rpx rgba(250, 81, 81, 0.40);
					position: absolute;
					top: 0;
					right: 0;
					color: white;
					transform: translate(90%, -70%);
				}
			}

		}
	}
</style>

<template>
	<view class="content">
		<view class="nav bgwhite" id="nav">
			<view>
				<Search @onConfirm="onConfirm" v-model="keywords" :iconType="CustomIconName.Add" @onIcon="$navTo(PagesProjectRouterConfig.AddProject)"></Search>

			</view>
			<u-tabs :list="nav" :is-scroll="false" bar-width="60" bar-height="4" :current="current" @change="change">
			</u-tabs>

		</view>
		<view :style="'height:'+navheight+'px;'"></view>
		<view v-if="navheight">
			<view class="lists" v-if="current!=2">
				<view class="list" v-for="item,index in list" :key="index">
					<view class="head flex">
						<view class="tips">
							<view class="tip f28 center-flex  actived" :style="'background:'+ State.LevelColor[item.level]+';'">
								{{item.level | itemLevel}}
							</view>
						</view>
						<view class="ordernum f28 gray">
							<view class="between-flex">
								<view class="f26 gray"></view>
								<view class="f26 bold" :style="'color:'+State.StateColor[item.showState]+';'">
									{{item.showState | itemProcessShow}}
								</view>
							</view>
						</view>
					</view>
					<view class="contains between-flex" @click="go(item)">
						<view class="text">
							<view class="textColor f34 bold">{{item.title}}</view>
							<view class="between-flex">
								<view class="gray m-right20">项目描述： </view><span class="textColor" style="width:460rpx;text-align: justify;">{{item.remark?item.remark:'无'}}</span>
							</view>
							<view class="between-flex line">
								<view class="align-flex">
									<view class="gray m-right20">负责人</view><span class="textColor">{{item.principal | user}}</span>
								</view>
								<view class="align-flex">
									<view class="gray m-right20">项目级别</view><span class="textColor">{{item.projectLevel | itemProjectLevel}}</span>
								</view>
							</view>

							<view class="align-flex">
								<view class="gray m-right20">项目类型： </view><span class="textColor">{{item.itemType==2?'新增':'优化'}}</span>
							</view>
							<view class="align-flex">
								<view class="gray m-right20">起止时间： </view><span class="textColor">{{item.startTime.substring(0,10)}}至{{item.endTime?item.endTime.substring(0,10):'-'}}</span>
							</view>
						</view>
						<u-icon name="arrow-right" color="#98a5b3" size="28"></u-icon>
					</view>

				</view>
			</view>
			<view class="lists" v-else>
				<view class="list" v-for="item,index in list" :key="index">
					<view class="head flex">
						<view class="tips">
							<view class="tip f28 center-flex bold " :class="isEnd(item)?'actived':'textColor'">
								{{isEnd(item)?'已超期':'未超期'}}
							</view>
						</view>
						<view class="ordernum f28 gray">
							<view class="between-flex">
								<view class="f26 gray">要求完成日期：{{item.endTime}}</view>

							</view>
						</view>
					</view>
					<view class="contains between-flex" @click="$navTo(PagesProjectRouterConfig.ProjectDetail+'?itemCode='+item.itemCode)">
						<view class="text">
							<view class="textColor f34 bold">{{item.title}}</view>
							<view class="align-flex">
								<view class="gray " style="width:125rpx;">负责人 </view><span class="textColor">{{item.principal | user}}</span>
							</view>

							<view class="line2 colum-flex">
								<view class="gray align-flex">项目进度 <view class="progress">
										<u-line-progress height="8" :show-percent="false" active-color="#409EFF" :percent="item.totalProgress"></u-line-progress>
									</view> <span class="textColor">{{item.totalProgress}}%</span> </view>
							</view>

						</view>
						<u-icon name="arrow-right" color="#98a5b3" size="28"></u-icon>
					</view>
					<view class="btns between-flex gray f24" v-if="!this.isFactory">
						<view class="btn center-flex" @click="$navTo(PagesProjectRouterConfig.Exchange+'?itemCode='+item.itemCode)">
							<view class="align-flex">
								<view class="num" v-if="item.applyNum">{{item.applyNum}}</view>
								<image src="../../static/images/project1.png" mode="aspectFit"></image> 变更申请
							</view>

						</view>
						<view class="btn center-flex" @click="$navTo(PagesHuiYiRouterConfig.Huiyi+'?itemCode='+item.itemCode)">
							<view class="align-flex">
								<view class="num" v-if="item.meetingNum">{{item.meetingNum}}</view>
								<image src="../../static/images/project2.png" mode="aspectFit"></image> 会议
							</view>

						</view>
						<view class="btn center-flex" @click="$navTo('/pages/fapiao/fapiao?itemCode='+item.itemCode)">
							<view class="align-flex">
								<view class="num" v-if="item.contractNum">{{item.contractNum}}</view>
								<image src="../../static/images/project3.png" mode="aspectFit"></image> 合同发票
							</view>

						</view>
					</view>
				</view>
			</view>
			<view class="center-flex c999 f24" v-if="nomore">-没有更多了-</view>
			<view v-if="empty" style="position: fixed;top:40%;left:50%;transform: translateX(-50%);">
				<u-empty text="暂无列表"></u-empty>

			</view>
		</view>



	</view>


</template>

<script>
	import PagesProjectRouterConfig from '@/pagesProject/routerConfig.js'
	import PagesDemandRouterConfig from '@/pagesDemand/routerConfig.js'
	import PagesHuiYiRouterConfig from '@/pagesHuiyi/routerConfig.js'
	import State from '@/pagesProject/state.js'
	import Search from '@/components/input/index.vue'
	import CustomIconName from '@/common/customIconFontName.js'
	import { Storage_IsFactory } from '@/common/index.js'
	export default {

		components: {
			Search
		},
		data() {
			return {
				CustomIconName,
				State,
				PagesProjectRouterConfig,
				PagesDemandRouterConfig,
				PagesHuiYiRouterConfig,
				navheight: 0,
				head: this.$head,
				nav: [{
						name: '方案制定',
						count: 0
					}, {
						name: '方案评审',
						count: 0
					},
					{
						name: '项目实施',
						count: 0
					}
				],
				current: 0,
				page: 1,
				list: [],
				nomore: false,
				empty: false,
				keywords: '',
				isFactory: false
			}
		},
		onLoad() {
			this.isFactory = Storage_IsFactory()
			console.log(uni.getStorageSync('dic'))
			// console.log(uni.getStorageSync('user'))
			setTimeout(() => {
				let info = uni.createSelectorQuery().select("#nav");
				info.boundingClientRect((data) => {

					this.navheight = data.height

					console.log(this.navheight)
				}).exec()

			}, 500)

		},
		onShow() {
			this.reset()

		},
		onReachBottom() {
			if (!this.nomore) {
				this.page++
				this.getlist()
			}
		},
		methods: {
			go(item) {
				if (this.current == 0) {
					this.$navTo(PagesDemandRouterConfig.DemandDetail + '?type=5&itemCode=' + item.itemCode)
					// this.$navTo(this.PagesProjectRouterConfig.AddProject+'?type=2&itemCode='+item.itemCode)
				} else if (this.current == 1) {
					this.$navTo(this.PagesProjectRouterConfig.ReviewDetail + '?itemCode=' + item.itemCode)
				}
			},
			isEnd(item) {

				var endTime = new Date((item.endTime).replace(/-/g, '/')).getTime()
				var nowTime = new Date().getTime()
				console.log(endTime - nowTime)
				if (nowTime < endTime) {
					return false
				} else {
					return true
				}


			},
			onConfirm() {
				this.$u.debounce(this.reset, 500)

			},
			reset() {
				this.$showloading()
				this.page = 1
				this.list = []
				this.nomore = false
				this.getlist()
				this.getRedInfo()
			},
			getlist() {
				var url = ''
				var obj = {
					query: this.keywords,
					pageNum: this.page,
					pageSize: 10
				}
				if (this.current == 0) {
					url = "/busItemInfo/getPage"
					obj.temp = 'program'
				} else if (this.current == 1) {
					url = "/busItemInfo/getPage"
					obj.temp = 'programReview'
				} else if (this.current == 2) {
					url = "/bus/wechat/my/item/page"
				}
				this.$pop.ajaxPost(url, obj).then(res => {
					uni.hideLoading()
					var list = res.body.list

					this.list = this.list.concat(list)

					if (this.list.length == 0) {
						this.empty = true
					} else {
						this.empty = false
						if (list.length < 10) {
							this.nomore = true
						} else {
							this.nomore = false
						}
					}
					// console.log(this.list)
				})
			},
			getRedInfo() {

				this.$pop.ajaxPost('/busItemInfo/getPage', {
					pageNum: 1,
					pageSize: 10,
					temp: 'program'
				}).then(res => {
					this.nav[0].count = res.body.total
				})

				this.$pop.ajaxPost('/busItemInfo/getPage', {
					pageNum: 1,
					pageSize: 10,
					temp: 'programReview'
				}).then(res => {
					this.nav[1].count = res.body.total
				})


				this.$pop.ajaxPost('/bus/wechat/my/item/page', {
					pageNum: 1,
					pageSize: 10
				}).then(res => {
					this.nav[2].count = res.body.total
				})

			},
			change(index) {

				this.current = index;
				this.reset()
			}

		}
	}
</script>
